/*
 * @Author: scl
 * @Date: 2023-09-06 17:13:03
 * @LastEditTime: 2023-09-06 22:04:22
 * @Description: file content
 */
/*
 * @lc app=leetcode.cn id=82 lang=typescript
 *
 * [82] 删除排序链表中的重复元素 II
 *
 * https://leetcode.cn/problems/remove-duplicates-from-sorted-list-ii/description/
 *
 * algorithms
 * Medium (53.58%)
 * Likes:    1176
 * Dislikes: 0
 * Total Accepted:    358.8K
 * Total Submissions: 669.5K
 * Testcase Example:  '[1,2,3,3,4,4,5]'
 *
 * 给定一个已排序的链表的头 head ， 删除原始链表中所有重复数字的节点，只留下不同的数字 。返回 已排序的链表 。
 * 
 * 
 * 
 * 示例 1：
 * 
 * 
 * 输入：head = [1,2,3,3,4,4,5]
 * 输出：[1,2,5]
 * 
 * 
 * 示例 2：
 * 
 * 
 * 输入：head = [1,1,1,2,3]
 * 输出：[2,3]
 * 
 * 
 * 
 * 
 * 提示：
 * 
 * 
 * 链表中节点数目在范围 [0, 300] 内
 * -100 <= Node.val <= 100
 * 题目数据保证链表已经按升序 排列
 * 
 * 
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * class ListNode {
 *     val: number
 *     next: ListNode | null
 *     constructor(val?: number, next?: ListNode | null) {
 *         this.val = (val===undefined ? 0 : val)
 *         this.next = (next===undefined ? null : next)
 *     }
 * }
 */

function deleteDuplicates(head: ListNode | null): ListNode | null {
    if (head==null||head.next==null) {
        return head;
    }
    let cur=new ListNode(0,head),bool=true
    while(head.next&&head.next.next){
        if(head.next.val==head.val){
            while(head.next&&head.next.val==head.val)head.next=head.next.next
        }else{
            head=head.next
            cur.next=head
            // if(bool)cur.next=head
        }
    }
    return cur.next
};
// @lc code=end

